<template>
<div>
   <van-form @submit="onSubmit">
  <van-field
    v-model="carnum"
    name="车牌号"
    label="车牌号"
    placeholder="车牌号"
    :rules="[{ required: true, message: '请填写车牌号' }]"
  />
<van-field
  
  readonly
  clickable
  label="车型"
  :value="models"
  placeholder="请选择车型"
  @click="showPicker = true"
/>
<van-popup v-model="showPicker" round position="bottom">
  <van-picker
    show-toolbar
    :columns="columns"
    @cancel="showPicker = false"
    @confirm="onConfirm"
  />
</van-popup>

  <div style="margin: 16px;">
    <van-button round block type="info" native-type="submit" >提交</van-button>
  </div>
</van-form>

</div>

</template>
<script>
import axios from 'axios';
import { Toast } from 'vant';

export default {
   name: "addCar",
  data() {
    return {
      carnum: '',
      value: '',
      models:'',
      showPicker: false,
      columns: ['大车', '小车', '摩托车'],
    };
  },
  methods: {
     
    onConfirm(models) {
      this.models = models;
      this.showPicker = false;
    },
     
    onSubmit() {
      this.$axios
      .post('car/addCar',{
        carnum: this.carnum,
        models: this.models
      })
      .then(res=>
      {
        console.log(res);
      alert("添加成功");

      // localStorage.setItem("carnum",this.carnum)
       this.$router.push("/parkspace"); 
      }).catch(error =>{
        console.log(error);
      });

      console.log('submit', values);
    },
  },
};
</script>

